<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class commonmodel extends Model {

    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }

    function country_list()
    {
        $sql = "SELECT * FROM tbl_country";
        $country_arr = $this->db->query($sql);
        return $country_list = $country_arr->result_array();
    }

    function get_city_by_country($country_id)
    {
        $sql = "SELECT city_id, city_name
                FROM tbl_city
                WHERE country_id = " . $country_id;
        $sql .= " order by  city_name asc ";
        $city_arr = $this->db->query($sql);
        return $city_list = $city_arr->result_array();
    }
      function get_featuredevent($langkey='uk')
    {
        $events_sql = "select * ,
                (select lvalue from tbl_lang b where b.lkey=a.eventtile and b.lang='{$langkey}') as eventtitle,
                (select lvalue from tbl_lang b where b.lkey=a.eventdsc and b.lang='{$langkey}') as eventdesc
                     from tbl_events a where a.status=1 and iseventofthemonth=1 ";
        $event = $this->db->query($events_sql);
        return $fevent = $event->row_array();
    }
      function get_event($id,$langkey='uk')
    {
        $events_sql = "select * ,
                (select lvalue from tbl_lang b where b.lkey=a.eventtile and b.lang='{$langkey}') as eventtitle,
                (select lvalue from tbl_lang b where b.lkey=a.eventdsc and b.lang='{$langkey}') as eventdesc
                     from tbl_events a where a.status=1 and id={$id} ";
        $event = $this->db->query($events_sql);
        return $fevent = $event->row_array();
    }
    
      function get_featuredvideos($id)
    {
        $video_sql = "select * 
                     from tbl_videos a where a.status=1 
                     order by default_video desc, RAND() limit 4";
        $event = $this->db->query($video_sql);
        return $fevent = $event->result_array();
    }
    
      function get_galleryimages($ishomebanner=0)
    {
          
        $where = " where ishomebanner={$ishomebanner}";         
        $sql = "select * 
                     from tbl_imagegallery 
                     {$where}
                     order by RAND() limit 8";
        $res = $this->db->query($sql);
        return $res_array = $res->result_array();
    }
    
    public function get_reviews(){        
        $reviews_sql = "select reviews_id,
                image,
                (select lvalue from tbl_lang b where b.lkey=a.title and b.lang='{$this->session->userdata("language")}' and module='reviews') as title
                from tbl_reviews a  
                    where a.status=1  
                ";                   
        $reviews = $this->db->query($reviews_sql);
        
        if($reviews->num_rows() > 0) {
            return $reviews_result = $reviews->result_array();
        }else{
            return FALSE;
        }
        
    }
    
    public function get_customlinks($link_id='0'){
        try{             
//            if($customlinks_page_id=='home'){
//                return FALSE;
//            }
            $where=" and id='{$link_id}'";
            $customlinks_sql = "select customlinks_id,   
                    a.customlinks_page_id,                    
                    (select lvalue from tbl_lang b where b.lkey=a.title and b.lang='{$this->session->userdata("language")}' and module='customlinks') as title ,
                    (select lvalue from tbl_lang b where b.lkey=a.desc and b.lang='{$this->session->userdata("language")}' and module='customlinks') as `desc` ,
                    a.image,
                    a.cost
                    from tbl_customlinks a   
            inner join tbl_links b on a.customlinks_page_id=b.id
                    where a.status=1  {$where}
                    
                    ";
                    
                     //echo $customlinks_sql;
        $customlinks = $this->db->query($customlinks_sql);
        if($customlinks->num_rows() > 0) {
                 return $customlinks_result = $customlinks->result_array();
            } else {
                return FALSE;
            }
        } catch(Exception $e){
            throw new Exception('Error in DB query');
            return FALSE;
        }
    }
    
        public function get_customlinks_iteneries($customlinks_id='0'){
        try{             
//            if($customlinks_page_id=='home'){
//                return FALSE;
//            }
            $where=" and customlinks_id='{$customlinks_id}'";
            $customlinks_sql = "select customlinks_id,   
                    a.customlinks_page_id,                    
                    (select lvalue from tbl_lang b where b.lkey=a.title and b.lang='{$this->session->userdata("language")}' and module='customlinks') as title ,
                    (select lvalue from tbl_lang b where b.lkey=a.desc and b.lang='{$this->session->userdata("language")}' and module='customlinks') as `desc` ,
                    a.image,
                    a.cost
                    from tbl_customlinks a   
            inner join tbl_links b on a.customlinks_page_id=b.id
                    where a.status=1  {$where}
                    
                    ";
                    
                     //echo $customlinks_sql;
        $customlinks = $this->db->query($customlinks_sql);
        if($customlinks->num_rows() > 0) {
                 return $customlinks_result = $customlinks->result_array();
            } else {
                return FALSE;
            }
        } catch(Exception $e){
            throw new Exception('Error in DB query');
            return FALSE;
        }
    }

    public function get_menulinks($link_type='', $link_id=0){ 
        $where='';
        if(!empty($link_type)){
            $where=" and link_type='{$link_type}' ";
        }
        if(!empty($link_id)){
            $where.=" and id='{$link_id}' ";
        }
        $menulinks_sql = "select * from tbl_links a  
                    where a.status=1  {$where}
                ";          
                    
        $menulinks = $this->db->query($menulinks_sql);
        
        if($menulinks->num_rows() > 0) {
            return $menulinks_result = $menulinks->result_array();
        }else{
            return FALSE;
        }
        
    }

    public function get_mainmenu_list($limit,$start, $customlinks_id='0'){
        try{             
//            if($mainmenu_page_id=='home'){
//                return FALSE;
//            }
            $where=" and a.customlinks_id='{$customlinks_id}'";
            $mainmenu_sql = "select mainmenu_id,   
                    (select link_text from tbl_links b inner join tbl_customlinks d on b.id=d.customlinks_page_id where d.customlinks_id=a.customlinks_id) as customlinks_id ,                 
                    (select lvalue from tbl_lang b where b.lkey=a.title and b.lang='{$this->session->userdata("language")}' and module='mainmenu') as title ,
                    (select lvalue from tbl_lang b where b.lkey=a.shortdesc and b.lang='{$this->session->userdata("language")}' and module='mainmenu') as `shortdesc` ,
                    (select lvalue from tbl_lang b where b.lkey=a.desc and b.lang='{$this->session->userdata("language")}' and module='mainmenu') as `desc` ,
                    a.image
                    from tbl_mainmenu a   
            inner join tbl_customlinks b on a.customlinks_id=b.customlinks_id
                    where a.status=1  {$where}
                    
                    ";
                    //if (!$where){
                     $mainmenu_sql.= " limit ".$start.",".$limit;
                    //}
                     //echo "mainmenu_sql: ".$mainmenu_sql;
        $mainmenu = $this->db->query($mainmenu_sql);
        if($mainmenu->num_rows() > 0) {
                 return $mainmenu_result = $mainmenu->result_array();
            } else {
                return FALSE;
            }
        } catch(Exception $e){
            throw new Exception('Error in DB query');
            return FALSE;
        }
    }
    
    public function get_mainmenu_list_count($customlinks_id=0) {

         try{
             $offer_type_id=  strtoupper($offer_type_id);
             if ($customlinks_id>0){
                 $where=" and customlinks_id='{$customlinks_id}' ";
             }
            $sql = "select  count(*) as count
                    from tbl_mainmenu 
                    where status=1 
                    {$where}
                    "
                        ;
        $mainmenu = $this->db->query($sql);
        if($mainmenu->num_rows() > 0) {
                 $offer_result = $mainmenu->row_array();
                  return $offer_result["count"];
            } else {
                return FALSE;
            }
        } catch(Exception $e){
            throw new Exception('Error in DB query');
            return FALSE;
        }
    }
    
    public function get_mainmenu_details($mainmenu_id=0){ 
        $where='';
        if(!empty($mainmenu_id)){
            $where=" and mainmenu_id='{$mainmenu_id}' ";
        }
        $menulinks_sql = "select 
                    mainmenu_id, 
                    customlinks_id,
                    (select link_text from tbl_links b where b.id=a.customlinks_id) as customlinks_page_text ,  
                    (select lvalue from tbl_lang b where b.lkey=a.title and b.lang='{$this->session->userdata("language")}' and module='mainmenu') as title ,
                    (select lvalue from tbl_lang b where b.lkey=a.desc and b.lang='{$this->session->userdata("language")}' and module='mainmenu') as `desc` ,
                    image
                    from tbl_mainmenu a  
                    where a.status=1  {$where}
                ";                   
        $menulinks = $this->db->query($menulinks_sql);
        
        if($menulinks->num_rows() > 0) {
            return $menulinks_result = $menulinks->result_array();
        }else{
            return FALSE;
        }
        
    }
    
    public function get_topmenu_details($topmenu_id=0){
        $where='';
        if(!empty($topmenu_id)){
            $where=" and customlinks_page_id='{$topmenu_id}' ";
        }
         $menulinks_sql = "select
                    customlinks_id,
                    customlinks_page_id,
                    (select link_text from tbl_links b where b.id=a.customlinks_page_id) as customlinks_page_text ,  
                    (select lvalue from tbl_lang b where b.lkey=a.title and b.lang='{$this->session->userdata("language")}' and module='customlinks') as title ,
                    (select lvalue from tbl_lang b where b.lkey=a.desc and b.lang='{$this->session->userdata("language")}' and module='customlinks') as `desc`
                    from tbl_customlinks a
                    where a.status=1  {$where}
                ";                   
        $menulinks = $this->db->query($menulinks_sql);
        
        if($menulinks->num_rows() > 0) {
            return $menulinks_result = $menulinks->result_array();
        }else{
            return FALSE;
        }
        
    }
}
?>
